<extend name="Public/base"/>
<block name="body">
    <h3>分类管理</h3>

    <!-- 表格列表 -->
    <div class="btn-group m-b-sm" role="group">
        <a class="btn btn-default" href="{:U('add')}">新 增</a>
    </div>
    <!-- /表格列表 -->
    <div class="panel-body panel panel-default">
        <table class="table table-hover table-striped">
            <thead>
                <tr>
                    <th>排序</th>
                    <th >发布</th>
                    <th>名称</th>
                    <th></th>
                </tr>
            </thead>
            <tbody class="category">
                {:R('Category/tree', array($tree))}
            </tbody>
        </table>
    </div>
</block>

<block name="script">
    <script type="text/javascript">
        $(document).ready(function () {
            /* 实时更新分类信息 */
            $(".category")
                    .on("submit", "form", function (e) {
                        e.preventDefault();
                        var self = $(this);
                        $.post(
                                self.attr("action"),
                                self.serialize(),
                                function (data) {
                                    if (data.status === 1) {
                                        $.scojs_message(data.info, $.scojs_message.TYPE_OK);
                                    }
                                    else
                                    if (data.status === 0) {
                                        $.scojs_message(data.info, $.scojs_message.TYPE_ERROR);
                                    }
                                },
                                "json"
                                );
                    })
                    .on("focus", "input", function () {
                        $(this).css("background-color", "#D6D6FF");
                    })
                    .on("blur", "input", function () {
                        $(this).css("background-color", '');
                        if ($(this).data('param') != $(this).closest("form").serialize()) {
                            $(this).closest("form").submit();
                        }
                    });
        });
    </script>
</block>
